#pragma once

#include <QWidget>
#include <qframe.h>
#include <qaction.h>
#include <qboxlayout.h>
#include <qtoolbar.h>
#include <qtabbar.h>
#include <qstring.h>
#include <qpushbutton.h>
#include <qmap.h>
#include <QVariant>


class VTabWidget : public QFrame
{
	Q_OBJECT

public:
	VTabWidget(QWidget*parent = nullptr);
	~VTabWidget();
	int addTab(QString title, QWidget *w, QWidget *expand = nullptr);
	QTabBar *tabBar();
	void setCurrentIndex(int index);
	QWidget *widget(int index);
	int count();
	QWidget* currentWidget();
	void removeTab(int index);
	void setTabData(int index, QVariant data);
	QVariant tabData(int index);
	void setTabsClosable(bool closable);
	void clearLayout(QBoxLayout *layout);
	void setHide(bool hide);

signals:
	void signalCurrentWidgetChanged(QWidget *w);

private:
	QTabBar *_tabbar;
	QToolBar *_toolbar;
	QWidget *_title_widget;
	QAction *_hide_action;
	QVBoxLayout *_vlayout;
	QHBoxLayout *_hlayout;
	QWidget *_widget;
	QHBoxLayout *_widget_layout;
	QWidget *_expand_widget;
	QHBoxLayout *_expand_widget_layout;

	void init_ui();
	void init_connect();

	QMap<QWidget*, QWidget*> _expand_map;
	QMap<QWidget*, QVariant> _tabDataMap;

private slots:
	void on_currentChanged(int index);
};


